package lu.med.praxiswahl.wahlumed.service.beans;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Remote;
import javax.ejb.Stateless;

import lu.med.praxiswahl.wahlumed.dao.beans.daointerface.CustomerDAOInt;
import lu.med.praxiswahl.wahlumed.dao.beans.daointerface.PhysicianLetterDAOInt;
import lu.med.praxiswahl.wahlumed.model.beans.PhysicianLetterTBL;
import lu.med.praxiswahl.wahlumed.service.beans.serviceinterface.PhysicianLetterServiceInt;

/**
 * Session Bean implementation class PhysicianLetterService
 */
@Stateless
@Remote({ PhysicianLetterServiceInt.class })
public class PhysicianLetterService implements PhysicianLetterServiceInt {

	@EJB
	private PhysicianLetterDAOInt letterDao;

	@EJB
	private CustomerDAOInt custDao;

	/**
	 * Default constructor.
	 */
	public PhysicianLetterService() {

	}

	@Override
	public void createLetter(PhysicianLetterTBL entry) {

		PhysicianLetterTBL tmpDocLetter_1 = new PhysicianLetterTBL();

		tmpDocLetter_1.setDatum(entry.getDatum());
		tmpDocLetter_1.setCustomer(custDao.findCustomerByRegisterNumber(entry
				.getCustomer().getMatrikel_nummer()));
		tmpDocLetter_1.setDocumentPath(entry.getDocumentPath());
		tmpDocLetter_1.setSender(entry.getSender());
		tmpDocLetter_1.setReceiver(entry.getReceiver());
		tmpDocLetter_1.setLastEditor(entry.getLastEditor());
		tmpDocLetter_1.setLastEditTime(entry.getLastEditTime());

		letterDao.persist(tmpDocLetter_1);

	}

	@Override
	public PhysicianLetterTBL[] retrieveEntriesByPatient(String matricule) {

		List<PhysicianLetterTBL> tmp = letterDao
				.findLetterByCustomer(matricule);
		PhysicianLetterTBL[] tmp_1 = new PhysicianLetterTBL[tmp.size()];

		for (int i = 0; i < tmp_1.length; i++) {
			tmp_1[i] = tmp.get(i);
		}
		return tmp_1;
	}

	@Override
	public void removeLetterEntry(Long id) {
		this.letterDao.delete(id);

	}

}
